version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;



generate row_num = _n;


forvalues i=0/25 {;
	generate col`i' = "";
};

local row = 4;
sort row_num;
order col0-col25;



foreach var in

	bl_child_age bl_child_female bl_child_in_school {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if bl_child_level == 1 & treatment_1 == 1 & baseline_household == 1;
	replace col2 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if bl_child_level == 1 & baseline_household == 1 & 
		pooled_treatment == 1, cluster(villcode); 
	test treatment_2;
	sig_p col3 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 3;

foreach var in 

	bl_household_size bl_number_child bl_education bl_farmer {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if bl_child_level == 1 & treatment_1 == 1 & baseline_household == 1;
	replace col2 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if bl_child_level == 1 & baseline_household == 1 & 
		pooled_treatment == 1, cluster(villcode); 
	test treatment_2;
	sig_p col3 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = 4;


foreach var in 
	fu_child_age fu_female bl_child_in_school fu_child_of_hh_head {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & treatment_1 == 1 [aw=hh_weight];
	replace col5 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if fu_young_child == 1 & fu_child_level == 1 &
		pooled_treatment == 1 [pw=hh_weight], cluster(villcode); 
	test treatment_2;
	sig_p col6 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 1;

foreach var in 
	
	fu_household_size fu_num_children fu_hh_head_edu fu_hh_head_occ_farmer 
	fu_total_land {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & treatment_1 == 1 [aw=hh_weight];
	replace col5 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if fu_young_child == 1 & fu_child_level == 1 &
		pooled_treatment == 1 [pw=hh_weight], cluster(villcode); 
	test treatment_2;
	sig_p col6 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = `row' + 1;

foreach var in 
	
	fu1c_ht_pukka fu1c_ht_semi_pukka fu1c_ht_kaccha fu1c_ht_thatched_huts 
	fu_num_goats fu_muslim_fiqa_sunni {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & treatment_1 == 1 [aw=hh_weight];
	replace col5 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if fu_young_child == 1 & fu_child_level == 1 &
		pooled_treatment == 1 [pw=hh_weight], cluster(villcode); 
	test treatment_2;
	sig_p col6 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 1;

foreach var in 
	
	fu_lang_urdu fu_lang_sindhi {; 
	
	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & treatment_1 == 1 [aw=hh_weight];
	replace col5 = string(r(mean), "$strformat") if row_num == `row';

	regress `var' treatment_2 if fu_young_child == 1 & fu_child_level == 1 &
		pooled_treatment == 1 [pw=hh_weight], cluster(villcode); 
	test treatment_2;
	sig_p col6 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 1;

reg treatment_2 
	bl_child_age bl_child_female bl_child_in_school
	bl_household_size bl_number_child bl_education bl_farmer
	if bl_child_level == 1 & baseline_household == 1 & pooled_treatment == 1, cluster(villcode); 
test
	bl_child_age = bl_child_female = bl_child_in_school =
	bl_household_size = bl_number_child = bl_education = bl_farmer = 0;
replace col3 = string(r(F), "$strformat") if row_num == `row';
replace col3 = string(r(p), "$strformat") if row_num == `row' + 1;



reg treatment_2 
	fu_child_age fu_female bl_child_in_school fu_child_of_hh_head
	fu_household_size fu_num_children fu_hh_head_edu fu_hh_head_occ_farmer 
	fu_total_land
	fu1c_ht_pukka fu1c_ht_semi_pukka fu1c_ht_kaccha fu1c_ht_thatched_huts 
	fu_num_goats fu_muslim_fiqa_sunni fu_lang_urdu fu_lang_sindhi
	if fu_young_child == 1 & fu_child_level == 1 & pooled_treatment == 1 [pw=hh_weight], cluster(villcode); 
test
	fu_child_age = fu_female = bl_child_in_school = fu_child_of_hh_head =
	fu_household_size = fu_num_children = fu_hh_head_edu = fu_hh_head_occ_farmer =
	fu_total_land =
	fu1c_ht_pukka = fu1c_ht_semi_pukka = fu1c_ht_kaccha = fu1c_ht_thatched_huts = 
	fu_num_goats = fu_muslim_fiqa_sunni = fu_lang_urdu = fu_lang_sindhi = 0;
replace col6 = string(r(F), "$strformat") if row_num == `row';
replace col6 = string(r(p), "$strformat") if row_num == `row' + 1;

local row = `row' + 2;

outsheet col0-col6 using "$dir/Table A1 Balance in Treat.csv" if
	row_num < `row', comma replace;



